Register Info
 MoleView

By PC Finch Software

(c) Copyright 1994

This program is PUBLIC DOMAIN. You are free to copy and distribute it as much as you like, in fact, I want you to. It may not, however, be sold or included as part of a sale of any other product without written permission from the author (ME!).

If you would like to register your copy of MoleView, then all you have to do is send me a POSTCARD. That's all! No cost.... IT'S FREE! Please send your postcard to the following address. If you would like to be informed of more software releases from PC Finch software then please let me know.

Peter C. Finch

P.O. Box 731

CHATSWOOD NSW 2057

AUSTRALIA

More Help


Help

What would you like to know more about

Why did I write MoleView

MOL File Format


Why did I write MoleView

The original purpose of MoleView was to write a fast 3D sphere drawing algorithm. All the Atoms in Moleview are actually 3D spheres. They are plotted in both the X, Y and Z directions. They are shaded using the Phong shading algorithm, and all the pixels are buffered using a pixel Z buffer technique. This causes the spheres in front to appear in front and means that spheres that touch are more accurately represented.

Once I had the above algorithms in place, I wanted some way to apply them and the mapping of Molecular structures seemed a logical choice. However, it is possible to use MoleView for things other than molecules (see FROSTY.MOL).

All the molecules are defined using a simple text file format, so you can create your own. This program could be used to show the structure of molecules to students learning chemistry, or used as a simple means of rendering them for reports, etc.

If you like MoleView and find it of some use and would like to register it then just send me a postcard. Most important, have fun.


MOL File Format

Moleview uses a simple Text file format to define where atoms are placed in a molecule. It also contains optional information detailing how the wire frame image will appear, when the molecule is rorated using the mouse. These files can be created and edited using any text editor, e.g. NOTPAD.EXE or DOS EDIT.COM.

The file is made up of a number of lines, each line starting with a command followed by a number of parameters. The parameters are seperated by tabs or spaces. The 2 possible commands are

; Example file format

ATOM	1	0 0 0	10	RED

LINE	1 2

Any line starting with a ; is ignored as a comment.

Your may have up to 256 separate ATOM commands and up to 256 separate LINE commands.


ATOM command format
ATOM command line format

ATOM	Place	X Y Z	Radius	Colour

The ATOM command places an ATOM somewhere in a 3D space. The Atoms are represented as shaded spheres in MoleView.

The ATOM command line contains 5 parameters.

Place	The Place parameter is an index reference for the atom. This is an integer number between 1 and 256. There can only be 1 atom per place so, for a particular molecule, Place must be unique. They can appear in any order (2,1,3,4) and can be skipped if required (1,2,10,11).

X Y Z	The next 3 parameters give the X Y and Z location, in a 3D space, for the centre of the ATOM. These 3 numbers can be either real or integers. The resulting molecule will be scaled to fit the window. The centre of the window is 0 0 0. +Z is towards you, -Z is away.

Radius	This is the radius of the ATOM. For example, it the ATOM was located at -10 0 0 and had a Radius of 10, then it would touch 0 0 0 and -20 0 0.

Colour	There are only 8 possible colours. They are BLACK, RED, YELLOW, BLUE, CYAN, MAGENTA, GREEN, and WHITE.

EXAMPLE


ATOM Example

The following list of ATOM comands will create the molecule show below.

; EXAMPLE1.MOL

ATOM	1	0 0 0	7	WHITE

ATOM	2	-10 0 0	3	RED

ATOM	3	10 0 0	3	GREEN

ATOM	4	0 10 0	3	YELLOW

ATOM	5	0 -10 0	3	BLUE

ATOM	6	0 0 10	3	CYAN

ATOM	7	0 0 -10	3	MAGENTA


LINE command format
LINE command line format

LINE	Place1 Place2

The LINE commands are optional.

What you grab the molecule with the mouse, a wire frame representation of the molecule is drawn using lines. When you move the mouse the wire frame molecule moves to give you visual feedback as to the orientation of the molecule.

This wire frame is created by connecting the centres of all the ATOMs together. The First Atom, e.g. Place 1, in the list is conected to the next, e.g. Place 2, and so on. For simple molecules this may give a good representation, however, for complex ones it is inadiquite. The LINE command lets you wire together different ATOMS and produce a better wire frame image.

The LINE command line conatins 2 parameters.

Place1 Place2	This is an integer number ranging from 1 to 256. It indicated that the ATOM in Place1 is connected to the ATOM in Place2. As a result, when the wire frame is drawn, a line will connect the two ATOMs.

You may have upto 256 LINEs in a single molecule. If LINEs are specified then the only those lines will appear in the wire frame.

EXAMPLE


LINE Example

The following shows the difference between an molecule with LINEs and one without. The lines will only appear while of molecule is being rotated.

Without LINEs

; EXAMPLE1.MOL

ATOM	1	0 0 0	7	WHITE

ATOM	2	-10 0 0	3	RED

ATOM	3	10 0 0	3	GREEN

ATOM	4	0 10 0	3	YELLOW

ATOM	5	0 -10 0	3	BLUE

ATOM	6	0 0 10	3	CYAN

ATOM	7	0 0 -10	3	MAGENTA

With LINEs

; EXAMPLE2.MOL

ATOM	1	0 0 0	7	WHITE

ATOM	2	-10 0 0	3	RED

ATOM	3	10 0 0	3	GREEN

ATOM	4	0 10 0	3	YELLOW

ATOM	5	0 -10 0	3	BLUE

ATOM	6	0 0 10	3	CYAN

ATOM	7	0 0 -10	3	MAGENTA

LINE	2 3

LINE	4 5

LINE	6 7


Pixel Z Buffer

A pixel Z Buffer is a way of drawing objects in a 3D seen so that the objects in front appear in front of objects behind them, regardless of the order in which they are drawn. First you require a 2D array (the Pixel Z Buffer) the same dimensions as the window you want to draw. The array is made up of integers, -32767 to +32768, One integer for every pixel in the window. Before you start drawing reset all the integers in the Z Buffer to - 32767, this indicates that the pixel at that location is as far away as possible.

When you go to plot a 3D pixel (X,Y,Z) first check to see if the integer value in the Z Buffer at location X,Y is less than the Z value of the pixel. If it is, then plot the pixel and set the value of the integer in the Z Buffer to the Z value of the Pixel, otherwise dont plot the pixel. If the next pixel you plot, at that location, is behind that pixel then the Z value in the Z Buffer will be less that  Z value of the pixel and the pixel will not be shown.

void Zplot(int x, int y, int z, int colour)

{

if(ZBuffer[x][y]<z) {

plot(x,y,colour) ;

Zbuffer[x][y]=z ;

}

}

The technique produces good results, it does however slow the plotting of each pixel down, and it does take up a lot of memory.